// pages/myapply/myapply.js
const app = getApp()
import api from '../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabControl: ['线上模拟考', '线下模拟考'],
    currentTabIndex: 0,
    progress: ['待支付', '已报名', '进行中','已完成'],
    currentProIndex: 0,
    exam_status: 1,
    status: 1,
    
    list:[],

    examTab: [
      { text: '报名列表', icon: '/images/apply.png', selectedIcon: '/images/apply_active.png' },
      { text: '我的报名', icon: '/images/myapply.png', selectedIcon: '/images/myapply_active.png' },
      { text: '个人中心', icon: '/images/profile.png', selectedIcon: '/images/profile_active.png' }
    ],
    currentTabbarIndex: 1
  },

  change(e) {
    this.setData({
      currentTabbarIndex: e.currentTarget.dataset.index
    })
    if (this.data.currentTabbarIndex == 0) {
      wx.redirectTo({
        url: '/pages/applylist/applylist',
      })
    } else if (this.data.currentTabbarIndex == 1) {
      wx.redirectTo({
        url: '/pages/myapply/myapply',
      })
    } else {
      wx.redirectTo({
        url: '/pages/profile/profile',
      })
    }

  },

  changeCurrentIndex(e){
    
    this.setData({
      currentTabIndex: e.currentTarget.dataset.index,
      exam_status: e.currentTarget.dataset.exam_status
    })
    
    this.getInit()
  },
  changeProgress(e){
    this.setData({
      currentProIndex: e.currentTarget.dataset.index,
      status: e.currentTarget.dataset.status
    })

    this.getInit()
  },

  getInit(){
    let obj = {}
    // obj.order_status = this.data.exam_status
    obj.exam_status = this.data.exam_status
    obj.status = this.data.status
    
    api.POST('applet/exam_order/finds', obj, res => {
      console.log(res)
      this.setData({
        list: res.data.data,
      })
      
      
      // 考点信息
      // for(let i=0; i<this.data.list.length; i++){

      //   if (this.data.list.province_name){
      //     this.data.list[i].venues = this.data.list.province_name + (this.data.list.city_name == null ? '' : this.data.list.city_name ) + (this.data.list.area_name == null ? '' : this.data.list.area_name)
      //   }
      // }

    })
  },

  goToOrderDetail(e){
    app.globalData.item_exam_id = e.currentTarget.dataset.exam_id
    console.log(e.currentTarget.dataset.exam_id)
    let oid = e.currentTarget.dataset.exam_order_id
    console.log(oid)
    if(this.data.exam_status == 1){
      if(this.data.status == 1){
        wx.navigateTo({
          url: '/pages/onlineUnpaid/onlineUnpaid?oid='+oid,
        })
      } else if (this.data.status == 2){
        wx.navigateTo({
          url: '/pages/onlineApplied/onlineApplied?oid=' + oid,
        })
      } else if (this.data.status == 3){
        wx.navigateTo({
          url: '/pages/onlineUnderway/onlineUnderway?oid=' + oid,
        })
      } else if (this.data.status == 4){
        wx.navigateTo({
          url: '/pages/onlineFinished/onlineFinished?oid=' + oid,
        })
      }
    } else if (this.data.exam_status == 2){
      if (this.data.status == 1){
        wx.navigateTo({
          url: '/pages/unpaid/unpaid?oid=' + oid,
        })
      } else if (this.data.status == 2){
        wx.navigateTo({
          url: '/pages/applied/applied?oid=' + oid,
        })
      } else if (this.data.status == 3){
        wx.navigateTo({
          url: '/pages/underway/underway?oid=' + oid,
        })
      } else if (this.data.status == 4){
        wx.navigateTo({
          url: '/pages/finished/finished?oid=' + oid,
        })
      }
    }
   
  },
  savePermit(){
    let that = this
    wx.setClipboardData({
      data: this.data.card.card_identifier,
      success(){
        wx.getClipboardData({
          success(res){
            wx.showToast({
              title: '保存准考证成功',
            })
            that.close()
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      isExam: true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getInit()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})